package com.weixin.common.utils;

import java.io.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author wangchunhui
 * @date 2023/2/1 15:21
 */
public class DateTransferUtil {

    public static String YYYY_MM_DD = "yyyy-MM-dd";
    public static String YYYYMMDD = "dd/MM/yyyy";

    public static void main(String[] args) throws Exception {
        String inPath = "C:\\Users\\Administrator\\Desktop\\日期转换文件夹\\日期转换20230201.txt";
        String outPath = "C:\\Users\\Administrator\\Desktop\\日期转换文件夹\\日期转换2023020102.txt";
        readFile(inPath, outPath);
    }

    public static void readFile(String inPath, String outPath) throws Exception {
        File readFile = new File(inPath);
        File writeFile = new File(outPath);
        FileInputStream fileInputStream = new FileInputStream(readFile);
        FileOutputStream fileOutputStream = new FileOutputStream(writeFile);

        BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream));
        String readStr = br.readLine();
        while (readStr != null) {
            String month = "";
            String day = "";
            String[] splits = readStr.split("/");
            if (splits[0].length() < 2) {
                day = "0" + splits[0];
            } else {
                day = splits[0];
            }
            if (splits[1].length() < 2) {
                month = "0" + splits[1];
            } else {
                month = splits[1];
            }
            String year = splits[2];
            String formatDate = year + "-" + month + "-" + day;
            fileOutputStream.write((formatDate + "\n").getBytes());
            readStr = br.readLine();
        }
        fileOutputStream.close();
        fileInputStream.close();
    }
}
